[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Jun 9 21:39:02 PDT 2004
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.211 -> 1.212
---
Log message:
Fix a bug in my checkin from last night that caused miscompilations of
186.crafty, fhourstones and 132.ijpeg.
Bugpoint makes really nasty miscompilations embarassingly easy to find. It
narrowed it down to the instcombiner and this testcase (from fhourstones):
bool %l7153_l4706_htstat_loopentry_2E_4_no_exit_2E_4(int* %i, [32 x int]* %works, int* %tmp.98.out) {
newFuncRoot:
%tmp.96 = load int* %i ; <int> [#uses=1]
%tmp.97 = getelementptr [32 x int]* %works, long 0, int %tmp.96 ; <int*> [#uses=1]
%tmp.98 = load int* %tmp.97 ; <int> [#uses=2]
%tmp.99 = load int* %i ; <int> [#uses=1]
%tmp.100 = and int %tmp.99, 7 ; <int> [#uses=1]
%tmp.101 = seteq int %tmp.100, 7 ; <bool> [#uses=2]
%tmp.102 = cast bool %tmp.101 to int ; <int> [#uses=0]
br bool %tmp.101, label %codeRepl4.exitStub, label %codeRepl3.exitStub
codeRepl4.exitStub: ; preds = %newFuncRoot
store int %tmp.98, int* %tmp.98.out
ret bool true
codeRepl3.exitStub: ; preds = %newFuncRoot
store int %tmp.98, int* %tmp.98.out
ret bool false
}
... which only has one combination performed on it:
$ llvm-as < t.ll | opt -instcombine -debug | llvm-dis
IC: Old = %tmp.101 = seteq int %tmp.100, 7 ; <bool> [#uses=1]
New = setne int %tmp.100, 0 ; <bool>:<badref> [#uses=0]
IC: MOD = br bool %tmp.101, label %codeRepl3.exitStub, label %codeRepl4.exitStub
IC: MOD = %tmp.97 = getelementptr [32 x int]* %works, uint 0, int %tmp.96 ; <int*> [#uses=1]
It doesn't get much better than this. :)
---
Diffs of the changes: (+1 -5)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.211 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.212
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.211 Wed Jun 9 21:12:35 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Jun 9 21:33:20 2004
@@ -1582,14 +1582,10 @@
return ReplaceInstUsesWith(I, ConstantBool::get(isSetNE));
// If we have ((X & C) == C), turn it into ((X & C) != 0).
- if (CI == BOC) {
- // Don't infinite loop if C is null and the & isn't folded yet.
- if (CI->isNullValue())
- return ReplaceInstUsesWith(I, ConstantBool::get(!isSetNE));
+ if (CI == BOC && isOneBitSet(CI))
return new SetCondInst(isSetNE ? Instruction::SetEQ :
Instruction::SetNE, Op0,
Constant::getNullValue(CI->getType()));
- }
// Replace (and X, (1 << size(X)-1) != 0) with x < 0, converting X
// to be a signed value as appropriate.
More information about the llvm-commits
mailing list