-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Closed
Labels
llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation
Description
Reproducer: https://alive2.llvm.org/ce/z/NQTmkh (Please use latest alive2 with AliveToolkit/alive2#1097)
define i32 @src(i32 %x) {
%ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)
%sub = sub i32 32, %ctlz
%shl = shl i32 1, %sub
%dec = add i32 %x, -1
%ult = icmp ult i32 %dec, -2
%sel = select i1 %ult, i32 %shl, i32 1
ret i32 %sel
}
define i32 @tgt(i32 %x) {
%ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)
%1 = sub nsw i32 0, %ctlz
%2 = and i32 %1, 31
%sel = shl nuw i32 1, %2
ret i32 %sel
}
----------------------------------------
define i32 @src(i32 %x) {
#0:
%ctlz = ctlz i32 %x, 0
%#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33
%sub = sub i32 32, %#range_0_%ctlz
%shl = shl i32 1, %sub
%dec = add i32 %x, 4294967295
%ult = icmp ult i32 %dec, 4294967294
%sel = select i1 %ult, i32 %shl, i32 1
ret i32 %sel
}
=>
define i32 @tgt(i32 %x) {
#0:
%ctlz = ctlz i32 %x, 0
%#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33
%#1 = sub nsw i32 0, %#range_0_%ctlz
%#2 = and i32 %#1, 31
%sel = shl nuw i32 1, %#2
ret i32 %sel
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
i32 %x = #xffffffff (4294967295, -1)
Source:
i32 %ctlz = #x00000000 (0)
i32 %#range_0_%ctlz = poison
i32 %sub = poison
i32 %shl = poison
i32 %dec = #xfffffffe (4294967294, -2)
i1 %ult = #x0 (0)
i32 %sel = #x00000001 (1)
Target:
i32 %ctlz = #x00000000 (0)
i32 %#range_0_%ctlz = poison
i32 %#1 = poison
i32 %#2 = poison
i32 %sel = poison
Source value: #x00000001 (1)
Target value: poison
Metadata
Metadata
Assignees
Labels
llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmiscompilation